package assdraw2.canvas.abstraction;


import java.util.Vector;

/**
 * 
 * Holds shapes in Z-axis order.
 * New shape is added in the end of the vector.
 * Use painters algorithm to paint in the correct order.
 * Implements bring to front and send to back functionality.
 * 
 */
public class ZOrderShapeList {

	private Vector<Shape> v;
	
	/**
	 * Constructs new instance 
	 */
	public ZOrderShapeList(){
		v = new Vector<Shape>();
	}
	
	/**
	 * Getter
	 * @return all shapes
	 */
	public Vector<Shape> getShapes(){
		return v;
	}
	
	public void setShapes(Vector<Shape> l){
		v = l;
	}
	
	/**
	 * Adds shapes to the end of the list (top layer; highest Z coordinate)
	 * @param s Shape
	 */
	public void addShape(Shape s){
		if(s!=null)
			v.add(v.size(), s);
	}
	
	/**
	 * Removes specified shape
	 * @param s Shape
	 */
	public void removeShape(Shape s){
		if(s!=null)
			for(int i=0;i<v.size();i++)
				if(v.get(i)==s){
					v.removeElementAt(i);
					break;
				}
	}
	
	/**
	 * Brings the shape to front (end of the list)
	 * @param s Shape
	 */
	public void bringToFront(Shape s){
		for(int i=0;i<v.size();i++)
			if(v.get(i)==s){
				v.removeElementAt(i);
				break;
			}
		v.add(v.size(), s);
	}

	/**
	 * Sends the shape to back (beginning of the list)
	 * @param s Shape
	 */
	public void sendToBack(Shape s){
		for(int i=0;i<v.size();i++)
			if(v.get(i)==s){
				v.removeElementAt(i);
				break;
			}
		v.add(0, s);
	}

}


